package net.jforum.util;

 

import java.util.Calendar;
import java.util.Date;

import net.jforum.entities.Topic;

import org.apache.commons.lang.StringUtils;

/**
 * @ author  张洋 jackson.zhang@ericsson.com
 * @ version 创建时间 ：Jun 11, 2010  10:18:36 AM
 * @ description : 
 */
public class CommonUtil {

	/**
	 * @param args
	 */
	public static boolean isEmpty(String str){
		if(str==null||str.trim().isEmpty()){
			return true;
		}
		return false;
	}
	public static boolean isNull(Object obj){
		return obj==null?true:false;
	}
	
	public static Date getDateWeekBefore(Date date){
		return new Date(date.getTime()-1000*60*60*24*7);
	}
	public static Date getDateMonthlyBefore(Date date){
		Calendar time=Calendar.getInstance();  
		time.setTime(date);   //设置时间为当前时间   
		time.add(Calendar.MONTH, -1); //月份减1 
		return time.getTime();
	}
	
	public static Date getTodayMorning(Date date){
		date.setHours(0);
		date.setMinutes(0);
		date.setSeconds(0);
		return date;
	}
	public static boolean isTopicPublishToday(Topic t){
		return t.getTime().after(getTodayMorning(new Date()));
	}
	
	
 
	public static String splitSearchKeyword(String input,String separator){
			 String inputString =input.trim();
			 String result=separator;
			 while(inputString.length()!=0){
				 int index=inputString.indexOf(" ");
				 if(index==-1){
					result=result+inputString+separator;
					 break;
				 }
				 String s=inputString.substring(0,index);
				result=result+s+separator;
				 inputString=inputString.substring(index,inputString.length()).trim();	 
			 }
			 return result;
	
	}
	
	public static void main(String[] args) {
		Date date=new Date();
		System.out.println(getDateWeekBefore(new Date()));
		// TODO Auto-generated method stub
		System.out.println(isEmpty("   "));
		System.out.println(isEmpty(null));
		System.out.println(isEmpty("2"));
		System.out.println(StringUtils.isBlank(" "));
		System.out.println(StringUtils.isBlank(null));
		
	}

}
